<template>
  <div class="singer_square">
    <my-scroll>
      <div class="outter">
        <div class="inner">
          <div class="selectbox">
            <div class="areabox">
              <div class="title">地区：</div>
              <template v-for="(item, index) in area">
                <div
                  :key="item.id"
                  class="areaitem"
                  :class="index == areaIndex ? 'active' : ''"
                  @click="changeArea(index)"
                >
                  {{ item.value }}
                </div>
              </template>
            </div>
            <div class="typebox">
              <div class="title">类型：</div>
              <template v-for="(item, index) in type">
                <div
                  :key="item.id"
                  class="typeitem"
                  :class="index == typeIndex ? 'active' : ''"
                  @click="changeType(index)"
                >
                  {{ item.value }}
                </div>
              </template>
            </div>
            <div class="screening">
              <div class="title">筛选：</div>
              <div class="screening_item">
                <template v-for="(item, index) in letter">
                  <span
                    :key="index"
                    class="typeitem"
                    :class="index == letterIndex ? 'active' : ''"
                    @click="changeLetter(index)"
                  >
                    {{ item }}
                  </span>
                </template>
              </div>
            </div>
          </div>
          <div class="singerbox">
            <div
              class="singeritem"
              v-for="(item, index) in singerList"
              :key="index"
              @click="gotoSinger(item)"
            >
              <div class="singerimage">
                <img class="" :src="item.picUrl + '?param=200y200'" />
              </div>
              <div class="singername">{{ item.name }}</div>
            </div>
          </div>
          <div class="more" @click="more">
            查看更多
          </div>
        </div>
      </div>
    </my-scroll>
  </div>
</template>

<script>
import request from "../../api/request"
export default {
  data() {
    return {
      total: 0,
      areaIndex: 0,
      typeIndex: 0,
      letterIndex: 0,
      singerList: [],
      limit: 21,
      page: 1,
      letter: ["热门"],
      type: [
        { id: -1, value: "全部" },
        { id: 1, value: "男歌手" },
        { id: 2, value: "女歌手" },
        { id: 3, value: "组合" },
      ],
      area: [
        { id: -1, value: "全部" },
        { id: 7, value: "华语" },
        { id: 96, value: "欧美" },
        { id: 8, value: "日本" },
        { id: 16, value: "韩国" },
        { id: 0, value: "其他" },
      ],
    }
  },
  created() {
    this.getSinger()
    this.getLetter()
  },
  methods: {
    async getSinger() {
      this.singerList = []
      let res = await request({
        url: "/artist/list",
        data: {
          type: this.type[this.typeIndex].id,
          area: this.area[this.areaIndex].id,
          initial: this.letterIndex == 0 ? -1 : this.letter[this.letterIndex],
          offset: (this.page - 1) * this.limit,
        },
        method: "get",
      })
      this.singerList.push(...res.artists)
    },
    changeArea(index) {
      this.areaIndex = index
      this.page = 1
      this.getSinger()
    },
    changeType(index) {
      this.typeIndex = index
      this.page = 1
      this.getSinger()
    },
    changeLetter(index) {
      this.letterIndex = index
      this.page = 1
      this.getSinger()
    },
    async more() {
      this.page++
      const res = await request({
        url: "/artist/list",
        data: {
          // cat: this.catList[this.areaIndex][this.typeIndex],
          type: this.type[this.typeIndex].id,
          area: this.area[this.areaIndex].id,
          initial: this.letterIndex == 0 ? -1 : this.letter[this.letterIndex],
          offset: (this.page - 1) * this.limit,
        },
        method: "get",
      })
      this.singerList.push(...res.artists)
    },
    // 生成26的字母
    getLetter() {
      for (var i = 0; i < 26; i++) {
        this.letter
        this.letter.push(String.fromCharCode(65 + i))
      }
    },
    gotoSinger(singer) {
      this.$router.push(`/musichome/singer?id=${singer.id}`)
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../../scss/common.scss";
.singer_square {
  width: 100%;
  height: 100%;
  .outter {
    width: 100%;
    display: flex;
    justify-content: center;
    .inner {
      width: 100%;
      max-width: 1200px;
      padding: 0px 20px;
    }
  }
}
.areabox {
  margin: 10px 20px;
  margin-top: 40px;
  font-size: 14px;
  display: flex;
  .areaitem {
    padding: 5px 0px;
    width: 60px;
    text-align: center;
  }
  .areaitem:not(:last-child) {
    border-right: 1px solid #ccc;
  }
  .areaitem:hover {
    cursor: pointer;
  }
}
.active {
  color: $primary;
  background: $bg;
}
.typebox {
  margin: 10px 20px;
  font-size: 14px;
  display: flex;
  .typeitem {
    padding: 5px 0px;
    width: 60px;
    text-align: center;
  }
  .typeitem:not(:last-child) {
    border-right: 1px solid #ccc;
  }
  .typeitem:hover {
    cursor: pointer;
  }
}
.title {
  font-weight: bold;
  font-size: 16px;
}
.screening {
  display: flex;
  margin: 0px 20px;
  .screening_item {
    width: calc(100% - 50px);
    display: flex;
    flex-wrap: wrap;
    span {
      padding: 5px 0px;
      display: inline-block;
      width: 40px;
      margin-bottom: 10px;
      text-align: center;
    }
    span:nth-child(1) {
      width: 60px;
    }
    span:hover {
      cursor: pointer;
    }
    span:not(:last-child) {
      border-right: 1px solid #ccc;
    }
  }
}
.singerbox {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .singeritem {
    width: 16.666%;
    margin-top: 30px;
    .singerimage {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
      img {
        width: 100%;
        height: auto;
        border-radius: 5px;
      }
    }
    .singername {
      font-size: 14px;
      width: 100%;
      text-align: center;
    }
  }
  .singeritem:hover {
    cursor: pointer;
  }
}
.more {
  width: 100%;
  text-align: center;
  display: block;
  line-height: 1rem;
  padding: 0.9rem 0rem;
  color: rgba(168, 168, 168, 0.8);
}
.more:hover {
  cursor: pointer;
}
@media (max-width: 600px) {
  .singer_square {
    padding-bottom: 60px;
    box-sizing: border-box;
  }
  .areabox {
    margin-top: 0.625rem;
    display: flex;
    .areaitem {
      padding: 5px 0px;
      width: 50px;
      font-size: 0.8125rem;
      text-align: center;
      vertical-align: middle;
    }
    .title {
      font-size: 0.8125rem;
      width: 3.125rem;
      height: 1.5625rem;
      line-height: 1.5625rem;
      vertical-align: middle;
    }
    .areaitem:not(:last-child) {
      border-right: 1px solid #ccc;
    }
    .areaitem:hover {
      cursor: pointer;
    }
  }
  .typebox {
    margin: 10px 20px;
    font-size: 14px;
    display: flex;
    .typeitem {
      font-size: 0.8125rem;
      width: 50px;
    }
    .typeitem:not(:last-child) {
      border-right: 1px solid #ccc;
    }
    .typeitem:hover {
      cursor: pointer;
    }
    .title {
      font-size: 0.8125rem;
      width: 3.125rem;
      height: 1.5625rem;
      line-height: 1.5625rem;
      vertical-align: middle;
    }
  }
  .screening {
    .screening_item {
      span {
        font-size: 0.8125rem;
        width: 1.875rem;
      }
      span:nth-child(1) {
        width: 2.5rem;
      }
    }
    .title {
      font-size: 0.8125rem;
      width: 3.125rem;
      height: 1.5625rem;
      line-height: 1.5625rem;
      vertical-align: middle;
    }
  }
  .singerbox {
    .singeritem {
      width: 50%;
    }
  }
}
</style>
